from common.base import BasePage
from selenium.webdriver.common.by import  By

from pages.addShoppingList import AddShoppingList
from pages.add_address import AddAddress
from pages.loginPage import LoginPage
from pages.regPage import RegPage


class FristPage(BasePage):

    seach_c=(By.CSS_SELECTOR, '#keyword')
    search_btn=(By.XPATH,"//input[@name='imageField']")
    reasul_tbn=(By.XPATH,"//form[@id='compareForm']//div[1]//a")
    # 购物车删除按钮
    delbtn = (By.LINK_TEXT, "删除")
    # 结算页面
    submitbt=(By.XPATH,'//*[@id="theForm"]/div[11]/h6/span')
    # 订单结算后
    listok=(By.XPATH,'/html/body/div[5]/div/h6')
    my=(By.LINK_TEXT,'我的账户')
    address=(By.PARTIAL_LINK_TEXT,"收货地址")


    def go_to_loginP(self):
         if self.getEleValue(self.login_unae) == '登录':
            self.getElement(*self.login_unae).click()

            return LoginPage(self.driver)
    # 跳转到注册
    def go_to_register(self):
        if self.getEleValue(self.reg_logout) == '注册':
            #点击注册按钮
            self.getElement(self.go_to_register()).click()
            #返回注册界面
            return RegPage(self.driver)

    def go_to_myaddress(self,username,password):
        self.go_to_loginP().denglu(username,password)
        self.getElement(self.my).click()
        self.getElement(self.address).click()
        return AddAddress(self.driver)

    #搜索商品
    def search(self):
        #找到文本框
        tx=self.getElement(*self.seach_c)
        # 清空文本框
        tx.clear()
        #输入值
        tx.send_keys('钻石')
        #点击搜索按钮
        self.getElement(*self.search_btn).click()
        # 点击搜索到的商品
        self.getElement(*self.reasul_tbn).click()

        return AddShoppingList(self.driver)

